Passed
Pull Request — master (#91)
by
unknown
07:33
created

qucosa.js ➔ fillOutServiceUrn   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 27
rs 8.8571
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A qucosa.js ➔ ... ➔ jQuery.getJSON 0 10 1
1
/**
2
 * This file is part of the TYPO3 CMS project.
3
 *
4
 * It is free software; you can redistribute it and/or modify it under
5
 * the terms of the GNU General Public License, either version 2
6
 * of the License, or any later version.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 *
11
 * The TYPO3 project - inspiring people to share!
12
 */
13
$(document).ready(function() {
14
    documentListConfirmDialog('#confirmDiscard');
15
    documentListConfirmDialog('#confirmPublish');
16
    documentListConfirmDialog('#confirmUpdate');
17
    documentListConfirmDialog('#confirmActivate');
18
    documentListConfirmDialog('#confirmInactivate');
19
    documentListConfirmDialog('#confirmRestore');
20
    documentListConfirmDialog('#confirmDelete');
21
    datepicker();
22
    jQuery('[data-toggle="tooltip"]').tooltip();
23
    $disableForm = jQuery('form[data-disabled]').attr('data-disabled');
0 ignored issues
show
Bug introduced by
The variable $disableForm seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.$disableForm.
Loading history...
24
    if ($disableForm) {
25
        jQuery('.input-field').each(function() {
26
            jQuery(this).attr('disabled', 'disabled');
27
        });
28
        jQuery('.rem_file_group').each(function() {
29
            jQuery(this).attr('disabled', 'disabled');
30
        });
31
        jQuery('.add_file_group').each(function() {
32
            jQuery(this).attr('disabled', 'disabled');
33
        });
34
        jQuery('.input_file_upload').each(function() {
35
            jQuery(this).attr('disabled', 'disabled');
36
        });
37
        jQuery('.add_field').each(function() {
38
            jQuery(this).attr('disabled', 'disabled');
39
        });
40
        jQuery('.add_group').each(function() {
41
            jQuery(this).attr('disabled', 'disabled');
42
        });
43
        jQuery('.rem_field').each(function() {
44
            jQuery(this).attr('disabled', 'disabled');
45
        });
46
        jQuery('.rem_group').each(function() {
47
            jQuery(this).attr('disabled', 'disabled');
48
        });
49
        jQuery('.fill_out_service_urn').each(function() {
50
            jQuery(this).attr('disabled', 'disabled');
51
        });
52
    }
53
    buttonFillOutServiceUrn();
54
    jQuery(".tx-dpf").on("click", ".rem_group", function() {
55
        jQuery(this).parents('fieldset').fadeOut(300, function() {
56
            jQuery(this).remove();
57
        });
58
        return false;
59
    });
60
    jQuery(".tx-dpf").on("click", ".rem_file_group", deleteFile);
61
    jQuery(".tx-dpf").on("click", ".rem_secondary_upload", function() {
62
        var dataIndex = jQuery(this).data("index");
0 ignored issues
show
Unused Code introduced by
The variable dataIndex seems to be never used. Consider removing it.
Loading history...
63
        jQuery(this).parents('.fs_file_group').fadeOut(300, function() {
64
            jQuery(this).remove();
65
        });
66
        return false;
67
    });
68
    jQuery(".tx-dpf").on("click", ".rem_field", function() {
69
        var dataIndex = jQuery(this).data("index");
0 ignored issues
show
Unused Code introduced by
The variable dataIndex seems to be never used. Consider removing it.
Loading history...
70
        var dataField = jQuery(this).data("field");
0 ignored issues
show
Unused Code introduced by
The variable dataField seems to be never used. Consider removing it.
Loading history...
71
        jQuery(this).parents('.form-group').fadeOut(300, function() {
72
            jQuery(this).remove();
73
        });
74
        return false;
75
    });
76
77
    initRadioGroupLinkedField();
78
79
    // Add metadata group
80
    jQuery(".tx-dpf").on("click", ".add_group", addGroup);
81
    jQuery(".tx-dpf").on("click", ".add_file_group", addGroup);
82
    jQuery(".tx-dpf").on("click", ".add_field", addField);
83
    jQuery(".tx-dpf").on("click", ".fill_out_service_urn", fillOutServiceUrn);
84
    jQuery(".tx-dpf").on("keyup", "input.urn", buttonFillOutServiceUrn);
85
    jQuery(".tx-dpf").on("change", ".form-radio-group input", setRadioGroupLinkedField);
86
87
    //jQuery(window).on("scroll", "", continuousScroll);
88
    jQuery(".tx-dpf").on("click", "#next", continuousScroll);
89
    // jQuery(".form-submit").on("click","#save",
90
    jQuery(".form-submit").on("click", "#save", validateFormAndSave);
91
    jQuery(".form-submit").on("click", "#validate", validateFormOnly);
92
93
    // hide 'more results' link
94
    var countResults = $('#search-results :not(thead) tr').length;
95
    var resultCount = $('#next').data('resultCount');
96
97
    if (countResults < resultCount) {
98
        jQuery("#next").hide();
99
    }
100
101
    addRemoveFileButton();
102
    
103
});
104
var validateFormAndSave = function() {
105
    jQuery("#validDocument").val("0");
106
    if (validateForm()) {
107
        jQuery("#validDocument").val("1");
108
        return true;
109
    }
110
    return false;
111
}
112
var validateFormOnly = function() {
113
    if (validateForm()) {
114
        showFormSuccess();
115
    }
116
    return false;
117
}
118
var validateForm = function() {
119
    var error = false;
120
    jQuery('span.mandatory-error').remove();
121
    jQuery('div.alert').remove();
122
    jQuery('.tx-dpf-tabs li a').each(function() {
123
        jQuery(this).removeClass('mandatory-error');
124
    });
125
    // check mandatory groups
126
    jQuery('fieldset[data-mandatory=1]').each(function() {
127
        var fieldset = jQuery(this);
128
        if (hasMandatoryInputs(fieldset)) {
129
            if (checkMandatoryInputs(fieldset)) {
130
                jQuery('<div class="alert alert-warning" role="alert"><span class="glyphicon glyphicon glyphicon-warning-sign pull-right"></span>' + form_error_msg_group_mandatory + '</div>').insertAfter(fieldset.find('legend').last());
0 ignored issues
show
Bug introduced by
The variable form_error_msg_group_mandatory seems to be never declared. If this is a global, consider adding a /** global: form_error_msg_group_mandatory */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
131
                showFormError();
132
                error = true;
133
                markPage(fieldset, true);
134
            }
135
        } else {
136
            if (checkFilledInputs(fieldset)) {
137
                jQuery('<div class="alert alert-warning" role="alert"><span class="glyphicon glyphicon glyphicon-warning-sign pull-right"></span>' + form_error_msg_group_one_required + '</div>').insertAfter(fieldset.find('legend').last());
0 ignored issues
show
Bug introduced by
The variable form_error_msg_group_one_required seems to be never declared. If this is a global, consider adding a /** global: form_error_msg_group_one_required */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
138
                showFormError();
139
                error = true;
140
                markPage(fieldset, true);
141
                error = true;
142
            }
143
        }
144
    });
145
    jQuery('fieldset[id=primary_file]').each(function() {
146
        var fieldset = jQuery(this);
147
        if (checkPrimaryFile(fieldset)) {
148
            jQuery('<div class="alert alert-warning" role="alert"><span class="glyphicon glyphicon glyphicon-warning-sign pull-right"></span>' + form_error_msg_group_mandatory + '</div>').insertBefore(fieldset.find('legend').last());
0 ignored issues
show
Bug introduced by
The variable form_error_msg_group_mandatory seems to be never declared. If this is a global, consider adding a /** global: form_error_msg_group_mandatory */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
149
            showFormError();
150
            error = true;
151
            markPage(fieldset, true);
152
        }
153
    });
154
    // check non mandatory groups
155
    jQuery('fieldset[data-mandatory=""]').each(function() {
156
        var fieldset = jQuery(this);
157
        var filledInputs = 0;
158
        jQuery(this).find('.input-field').each(function() {
159
            if (jQuery(this).val() && jQuery(this).attr('data-default') != '1') {
160
                filledInputs++;
161
            }
162
            jQuery(this).removeClass('mandatory-error');
163
        });
164
        // if there are fields with a value then mandatory fields
165
        // are relevant.
166
        if (filledInputs) {
167
            if (checkMandatoryInputs(fieldset)) {
168
                jQuery('<div class="alert alert-warning" role="alert"><span class="glyphicon glyphicon glyphicon-warning-sign pull-right"></span>' + form_error_msg_group_mandatory + '</div>').insertAfter(fieldset.find('legend').last());
0 ignored issues
show
Bug introduced by
The variable form_error_msg_group_mandatory seems to be never declared. If this is a global, consider adding a /** global: form_error_msg_group_mandatory */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
169
                showFormError();
170
                markPage(fieldset, true);
171
                error = true;
172
            }
173
        }
174
    });
175
    jQuery('fieldset').each(function() {
176
        var fieldset = jQuery(this);
177
        fieldset.find('.input-field').each(function() {
178
            jQuery(this).removeClass('invalid-error');
179
            var validation = jQuery(this).attr('data-regexp');
180
            if (jQuery(this).val() && jQuery(this).val().length > 0 && validation && validation.length > 0) {
181
                try {
182
                    var regexp = new RegExp(validation);
183
                    var res = jQuery(this).val().match(regexp);
184
                    if (!(res && res.length == 1 && res[0] == jQuery(this).val())) {
185
                        jQuery('<div class="alert alert-warning" role="alert"><span class="glyphicon glyphicon glyphicon-warning-sign pull-right"></span>' + form_error_msg_field_invalid + ': ' + jQuery(this).attr('data-label') + '</div>').insertAfter(fieldset.find('legend').last());
0 ignored issues
show
Bug introduced by
The variable form_error_msg_field_invalid seems to be never declared. If this is a global, consider adding a /** global: form_error_msg_field_invalid */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
186
                        jQuery(this).addClass('invalid-error');
187
                        showFormError();
188
                        markPage(fieldset, true);
189
                        error = true;
190
                    }
191
                } catch (err) {
192
                    jQuery('<div class="alert alert-warning" role="alert"><span class="glyphicon glyphicon glyphicon-warning-sign pull-right"></span>' + form_error_msg_field_invalid + ': ' + jQuery(this).attr('data-label') + '</div>').insertAfter(fieldset.find('legend').last());
193
                    jQuery(this).addClass('invalid-error');
194
                    showFormError();
195
                    markPage(fieldset, true);
196
                    error = true;
197
                }
198
            } else {
199
                var validateDate = jQuery(this).attr('data-datatype') == 'DATE';
200
                if (jQuery(this).val() && jQuery(this).val().length > 0 && validateDate && !isDate(jQuery(this).val())) {
201
                    jQuery('<div class="alert alert-warning" role="alert"><span class="glyphicon glyphicon glyphicon-warning-sign pull-right"></span>' + form_error_msg_field_invalid + ': ' + jQuery(this).attr('data-label') + '</div>').insertAfter(fieldset.find('legend').last());
202
                    jQuery(this).addClass('invalid-error');
203
                    showFormError();
204
                    markPage(fieldset, true);
205
                    error = true;
206
                }
207
            }
208
        });
209
        /*        if (checkPrimaryFile(fieldset)) {
210
                  jQuery('<div class="alert alert-warning" role="alert"><span class="glyphicon glyphicon glyphicon-warning-sign pull-right"></span>'+form_error_msg_group_mandatory+'</div>').insertBefore(fieldset.find('legend').last());
211
                  showFormError();   
212
                  error = true;
213
                  markPage(fieldset,true);        
214
                }
215
          */
216
    });
217
    return !error;
218
}
219
var showFormError = function() {
220
    jQuery('.tx-dpf div.alert-danger').remove();
221
    jQuery('<div class="alert alert-danger" role="alert"><span class="glyphicon glyphicon glyphicon-fire pull-right"></span>' + form_error_msg + '</div>').insertBefore(jQuery('.tx-dpf form').first());
0 ignored issues
show
Bug introduced by
The variable form_error_msg seems to be never declared. If this is a global, consider adding a /** global: form_error_msg */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
222
    jQuery("html, body").animate({
223
        scrollTop: 0
224
    }, 200);
225
}
226
var showFormSuccess = function() {
227
    jQuery('.tx-dpf div.alert-danger').remove();
228
    jQuery('<div class="alert alert-success" role="alert"><span class="glyphicon glyphicon glyphicon-fire pull-right"></span>' + form_success_msg + '</div>').insertBefore(jQuery('.tx-dpf form').first());
0 ignored issues
show
Bug introduced by
The variable form_success_msg seems to be never declared. If this is a global, consider adding a /** global: form_success_msg */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
229
    jQuery("html, body").animate({
230
        scrollTop: 0
231
    }, 200);
232
}
233
var hasMandatoryInputs = function(fieldset) {
234
    var inputs = fieldset.find(".input-field[data-mandatory=1]");
235
    return inputs.length > 0
236
}
237
var markPage = function(fieldset, error) {
238
    var pageId = fieldset.parent().attr('id');
239
    var page = jQuery('.tx-dpf-tabs li a[href=#' + pageId + ']');
240
    if (error) {
241
        page.addClass('mandatory-error');
242
    } else {
243
        page.removeClass('mandatory-error');
244
    }
245
}
246
var checkMandatoryInputs = function(fieldset) {
247
    var mandatoryError = false;
248
249
    fieldset.find(".input-field[data-mandatory=1]").each(function () {
250
            var id = jQuery(this).attr('id');
251
252
            if (jQuery(this).attr('type') == 'radio') {
253
                var radioName = jQuery(this).attr('name');
254
                if (!jQuery('input[name="'+radioName+'"]').is(":checked")) {
255
                    mandatoryError = mandatoryError || true;
256
                    jQuery(this).addClass('mandatory-error');
257
                }  else {
258
                    jQuery(this).removeClass('mandatory-error');
259
                }
260
            } else {
261
                if (
262
                    (jQuery(this).attr('type') != 'checkbox' && !jQuery(this).val()) ||
263
                    (
264
                        jQuery(this).attr('type') == 'checkbox' &&
265
                        (jQuery("#" + id + ":checked").length != 1 || !jQuery("#" + id + ":checked"))
266
                    )
267
                ) {
268
                    mandatoryError = mandatoryError || true;
269
                    jQuery(this).addClass('mandatory-error');
270
                } else {
271
                    jQuery(this).removeClass('mandatory-error');
272
                }
273
            }
274
        });
275
276
    //markPage(fieldset,mandatoryError);
277
    return mandatoryError;
278
}
279
var checkPrimaryFile = function(fieldset) {
280
    var mandatoryError = false;
281
    fieldset.find("input#inp_primaryFile[data-virtual!=1]").each(function() {
282
        if (!jQuery(this).val()) {
283
            mandatoryError = mandatoryError || true;
284
            jQuery(this).addClass('mandatory-error');
285
        } else {
286
            jQuery(this).removeClass('mandatory-error');
287
        }
288
    });
289
    //  markPage(fieldset,mandatoryError);
290
    return mandatoryError;
291
}
292
var checkFilledInputs = function(fieldset) {
293
    var filledInputs = 0;
294
    fieldset.find('.input-field').each(function() {
295
        if (jQuery(this).val()) {
296
            filledInputs++;
297
        }
298
        jQuery(this).removeClass('mandatory-error');
299
    });
300
    //markPage(fieldset,filledInputs < 1);    
301
    return filledInputs < 1;
302
}
303
var addGroup = function() {
304
    var element = jQuery(this);
305
    // Get the group uid
306
    var dataGroup = jQuery(this).attr('data-group');
307
    // Number of the next group item
308
    // var groupIndex = jQuery(this).parent().find('fieldset[data-group="'+dataGroup+'"]').length;
309
    var groupIndex = parseInt(jQuery(this).attr('data-index')) + 1;
310
    jQuery(this).attr('data-index', groupIndex);
311
    var ajaxURL = jQuery(this).attr('data-ajax');
312
    var params = buildAjaxParams(ajaxURL, "groupIndex", groupIndex);
313
    //do the ajax-call
314
    jQuery.post(ajaxURL, params, function(group) {
315
        var group = jQuery(group).find("fieldset");
316
        // add the new group
317
        jQuery(group).css({
318
            'display': 'none'
319
        }).insertAfter(jQuery('fieldset[data-group="' + dataGroup + '"]').last());
320
        var height = jQuery('fieldset[data-group="' + dataGroup + '"]').last().outerHeight(true)
321
        jQuery('html, body').animate({
322
            scrollTop: element.offset().top - height
323
        }, 400, function() {
324
            jQuery(group).fadeIn();
325
        });
326
        buttonFillOutServiceUrn();
327
        datepicker();
328
        addRemoveFileButton();
329
    });
330
    return false;
331
}
332
var addField = function() {
333
    var addButton = jQuery(this);
334
    // Get the field uid
335
    var dataField = jQuery(this).attr('data-field');
0 ignored issues
show
Unused Code introduced by
The variable dataField seems to be never used. Consider removing it.
Loading history...
336
    // Number of the next field item      
337
    var fieldIndex = parseInt(jQuery(this).attr('data-index')) + 1;
338
    jQuery(this).attr('data-index', fieldIndex);
339
    var ajaxURL = jQuery(this).attr('data-ajax');
340
    var params = buildAjaxParams(ajaxURL, "fieldIndex", fieldIndex);
341
    //do the ajax-call       
342
    jQuery.post(ajaxURL, params, function(element) {
343
        var field = jQuery(element).find("#new-element").children();
344
        jQuery(field).css({
345
            'display': 'none'
346
        }).insertBefore(addButton).fadeIn();
347
        buttonFillOutServiceUrn();
348
        datepicker();
349
        //  var height =jQuery('input[data-field="'+dataField+'"][data-index="'+fieldIndex+'"]').last().outerHeight(true)
350
        // jQuery('html, body').animate({
351
        //   scrollTop: element.offset().top - height
352
        //}, 400);
353
    });
354
    return false;
355
}
356
var deleteFile = function() {
357
    var fileGroup = jQuery(this).parent().parent();
358
    //jQuery(this).parent().remove();
359
    var ajaxURL = jQuery(this).attr('data-ajax');
360
    //var params = buildAjaxParams(ajaxURL,"fileUid",fieldIndex);
361
    var params = {}
362
        //do the ajax-call       
363
    jQuery.post(ajaxURL, params, function(element) {
364
        var field = jQuery(element).find("#new-element").children();
365
        jQuery(fileGroup).replaceWith(field);
366
    });
367
    return false;
368
}
369
370
function buildAjaxParams(ajaxURL, indexName, index) {
371
    var res = ajaxURL.match(/(tx\w+?)%/); // get param name
372
    var params = {};
373
    var indexParam = {};
374
    if (res && res[1]) {
375
        indexParam[indexName] = index;
376
        params[res[1]] = indexParam;
377
    }
378
    return params;
379
}
380
var fillOutServiceUrn = function() {
381
    // Get the field uid
382
    var fieldUid = jQuery(this).attr('data-field');
383
    var fieldIndex = jQuery(this).attr('data-index');
384
    var groupUid = jQuery(this).attr('data-group');
385
    var groupIndex = jQuery(this).attr('data-groupindex');
386
    var ajaxURL = jQuery(this).attr('data-ajax');
387
    var qucosaId = jQuery('#qucosaid').val();
388
    var params = {};
0 ignored issues
show
Unused Code introduced by
The assignment to variable params seems to be never used. Consider removing it.
Loading history...
389
    if (qucosaId) {
390
        params = buildAjaxParams(ajaxURL, "qucosaId", qucosaId);
391
    } else {
392
        params = buildAjaxParams(ajaxURL, "qucosaId", "");
393
    }
394
    //do the ajax-call       
395
    jQuery.getJSON(ajaxURL, params, function(element) {
396
        jQuery('#qucosaid').val(element.qucosaId);
397
        jQuery('#qucosaUrn').val(element.value);
398
        //var inputField = jQuery('.input-field[data-field="'+ fieldUid +'"][data-index="'+ fieldIndex +'"]');                  
399
        var inputField = jQuery('.input-field[data-field="' + fieldUid + '"][data-index="' + fieldIndex + '"][data-group="' + groupUid + '"][data-groupindex="' + groupIndex + '"]');
400
        inputField.val(element.value);
401
        //var fillOutButton = jQuery('.fill_out_service_urn[data-field="'+ fieldUid +'"][data-index="'+ fieldIndex +'"]');           
402
        //fillOutButton.hide();           
403
        buttonFillOutServiceUrn();
404
    });
405
    return false;
406
}
407
var buttonFillOutServiceUrn = function() {
408
    jQuery('input.urn').each(function() {
409
        var fieldUid = jQuery(this).attr('data-field');
410
        var fieldIndex = jQuery(this).attr('data-index');
411
        var groupUid = jQuery(this).attr('data-group');
0 ignored issues
show
Unused Code introduced by
The variable groupUid seems to be never used. Consider removing it.
Loading history...
412
        var groupIndex = jQuery(this).attr('data-groupindex');
0 ignored issues
show
Unused Code introduced by
The variable groupIndex seems to be never used. Consider removing it.
Loading history...
413
        var fillOutButton = jQuery('.fill_out_service_urn[data-field="' + fieldUid + '"][data-index="' + fieldIndex + '"]');
414
        if ((jQuery(this).val() && jQuery(this).val().length > 0) || hasQucosaUrn()) {
415
            fillOutButton.hide();
416
        } else {
417
            fillOutButton.show();
418
        }
419
    });
420
    return false;
421
}
422
var hasQucosaUrn = function() {
423
    var result = false;
424
    var qucosaUrn = jQuery('#qucosaUrn').val();
425
    jQuery('input.urn').each(function() {
426
        var currentUrn = jQuery(this).val();
427
        if (currentUrn && qucosaUrn && (currentUrn == qucosaUrn)) {
428
            result = result || true;
429
        }
430
    });
431
    return result;
432
}
433
var continuousScroll = function() {
434
    var ajaxURL = jQuery("#next").attr('href');
435
    jQuery.ajax({
436
        url: ajaxURL,
437
        success: function(html) {
438
            if (html) {
439
                jQuery(html).find("table tbody tr").each(function() {
440
                    jQuery("#search-results tbody tr").last().parent().append(this);
441
                });
442
                if (jQuery(html).find("table tbody tr").length <= 0) {
443
                    jQuery("#next").hide();
444
                }
445
            } else {
446
                jQuery("#next").hide();
447
            }
448
        }
449
    });
450
    return false;
451
}
452
$(window).scroll(function() {
453
    if ($(this).scrollTop() > 330) {
454
        $(".tx-dpf-tab-container").addClass("sticky");
455
    } else {
456
        $(".tx-dpf-tab-container").removeClass("sticky");
457
    }
458
});
459
var datepicker = function() {
460
    var language = jQuery('div.tx-dpf[data-language]').first().attr('data-language');
461
    if (!language) language = "en";
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
462
    jQuery('.datetimepicker').datetimepicker({
463
        useCurrent: false,
464
        format: 'DD.MM.YYYY',
465
        locale: language,
466
        keepInvalid: true
467
    });
468
}
469
var isDate = function(value) {
470
    if (value == '') return false;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
471
    var rxDatePattern = /^(\d{1,2})(\.)(\d{1,2})(\.)(\d{4})$/; //Declare Regex
472
    var dtArray = value.match(rxDatePattern); // is format OK?
473
    if (dtArray == null) return false;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
474
    //Checks for mm/dd/yyyy format.
475
    dtMonth = dtArray[3];
0 ignored issues
show
Bug introduced by
The variable dtMonth seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.dtMonth.
Loading history...
476
    dtDay = dtArray[1];
0 ignored issues
show
Bug introduced by
The variable dtDay seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.dtDay.
Loading history...
477
    dtYear = dtArray[5];
0 ignored issues
show
Bug introduced by
The variable dtYear seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.dtYear.
Loading history...
478
    if (dtMonth < 1 || dtMonth > 12) {
479
        return false;
480
    } else if (dtDay < 1 || dtDay > 31) {
481
        return false;
482
    } else if ((dtMonth == 4 || dtMonth == 6 || dtMonth == 9 || dtMonth == 11) && dtDay == 31) {
483
        return false;
484
    } else if (dtMonth == 2) {
485
        var isleap = (dtYear % 4 == 0 && (dtYear % 100 != 0 || dtYear % 400 == 0));
486
        if (dtDay > 29 || (dtDay == 29 && !isleap)) return false;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
487
    }
488
    return true;
489
}
490
var documentListConfirmDialog = function(dialogId) {
491
    jQuery(dialogId).modal({
492
        show: false,
493
        backdrop: 'static'
494
    });
495
    jQuery(dialogId).on('show.bs.modal', function(e) {
496
        jQuery(this).find('#discardDocument').attr('href', jQuery(e.relatedTarget).attr('href'));
497
        var bodyText = jQuery(this).find('.modal-body p').html();
498
        var title = jQuery(e.relatedTarget).attr('data-documenttitle');
499
        jQuery(this).find('.modal-body p').html(bodyText.replace('%s', title));
500
        jQuery(e.relatedTarget).parent().parent().addClass('danger marked-for-removal');
501
    });
502
    jQuery(dialogId).on('hidden.bs.modal', function(e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
503
        jQuery('.marked-for-removal').removeClass('danger marked-for-removal');
504
    });
505
}
506
507
function addRemoveFileButton() {
508
    $('.rem_file').unbind('click');
509
    $('.rem_file').bind('click', function (evt) {
510
        evt.preventDefault();
511
        $(this).siblings('.input_file_upload').val('');
512
    })
513
}
514
515
var setRadioGroupLinkedField = function(event) {
516
        var fieldUid = jQuery(event.target).attr('data-field');
0 ignored issues
show
Unused Code introduced by
The variable fieldUid seems to be never used. Consider removing it.
Loading history...
517
        var fieldIndex = jQuery(event.target).attr('data-index');
518
        var groupUid = jQuery(event.target).attr('data-group');
519
        var groupIndex = jQuery(event.target).attr('data-groupindex');
520
        var linkedFieldUid = jQuery(event.target).data('linkedfield');
521
        var linkedValue = jQuery(event.target).data('linkedvalue').trim();
522
        var linkedField = jQuery('[data-field="' + linkedFieldUid + '"][data-index="' + fieldIndex + '"][data-group="' + groupUid + '"][data-groupindex="' + groupIndex + '"]');
523
524
        linkedField.val(linkedValue);
525
}
526
527
528
var initRadioGroupLinkedField = function() {
529
530
    var element = jQuery('.form-radio-group input:checked');
531
532
    if (element.length > 0) {
533
        var fieldUid = element.attr('data-field');
0 ignored issues
show
Unused Code introduced by
The variable fieldUid seems to be never used. Consider removing it.
Loading history...
534
        var fieldIndex = element.attr('data-index');
535
        var groupUid = element.attr('data-group');
536
        var groupIndex = element.attr('data-groupindex');
537
        var linkedFieldUid = element.data('linkedfield');
538
        var linkedValue = element.data('linkedvalue').trim();
539
        var linkedField = jQuery('[data-field="' + linkedFieldUid + '"][data-index="' + fieldIndex + '"][data-group="' + groupUid + '"][data-groupindex="' + groupIndex + '"]');
540
541
        linkedField.val(linkedValue);
542
    }
543
}
544